

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="NetworkManager command line tool">
  <meta name="author" content="kinzun">
  <meta name="keywords" content>
  <meta name="description" content="NetworkManager command line tool">
<meta name="keywords" content="Network">
<meta property="og:type" content="article">
<meta property="og:title" content="NetworkManager command line tool">
<meta property="og:url" content="https://kinzun.github.io/2017/03/07/NetworkManager-command-line-tool/index.html">
<meta property="og:site_name" content="kinzun">
<meta property="og:description" content="NetworkManager command line tool">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-10-04T08:12:40.000Z">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="NetworkManager command line tool">
<meta name="twitter:description" content="NetworkManager command line tool">
  
  <title>NetworkManager command line tool - kinzun</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css">
  <link rel="stylesheet" href="/lib/hint/hint.min.css">

  
    
    
      
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css">
    
  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">

<link rel="stylesheet" href="/css/main.css">

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"kinzun.github.io","root":"/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/local-search.xml"};
  </script>
  <script src="/js/utils.js"></script>
  <script src="/js/color-schema.js"></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>kinzun</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="NetworkManager command line tool">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2017-03-07 14:32" pubdate>
        2017年3月7日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      5.8k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      18 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">NetworkManager command line tool</h1>
            
            <div class="markdown-body">
              <p>NetworkManager command line tool</p>
<a id="more"></a>
<div class="hljs code-wrapper"><pre><code>nmcli
 nmcli [ OPTIONS ] OBJECT { COMMAND | help }

    要得到系统中所有接口的地址信息
        ip addr show
    检索与已连接的接口相关的数据包统计
        ip -s link show eno16777736 
        ip route 
    分析主机/网站路径
        tracepath linxu.com 
    仅显示当前活动的连接。
        nmcli device status
    查看新连接的配置信息：
        nmcli -p connection show NEW

    更新启用连接：
            nmcli connection up eno1
            nmcli con reload

启动/停止 网络接口
    使用下列命令停止某个接口：
        nmcli device disconnect eno16777736
    下列命令用来启动接口：
        nmcli device connect eno16777736

add
    找出有多少连接服务于多少设备
        nmcli connection show 
        //nmcli connection show eno1

    得到网络设备状态
        nmcli connection status 

    使用“dhcp”创建新的连接
        nmcli connection add con-name &quot;dhcp&quot; type ethernet ifname eno16777736 
            connection add – 添加新的连接
            con-name – 连接名
            type – 设备类型
            ifname – 接口名

            autoconnect no – 禁止开机自动启动

            ipv4.method manual | dhcp 静态IP或DHCP获取


    添加静态IP的以太网连接
        nmcli connection add type ethernet con-name NAME_OF_CONNECTION ifname interface-name ip4 IP_ADDRESS gw4 GW_ADDRESS

        nmcli connection add type ethernet con-name NEW ifname eno16777736 ip4 192.168.1.141 gw4 192.168.1.1                

            不通过dhcp分配IP，使用“static”添加地址
                nmcli connection add con-name &quot;static&quot; ifname eno16777736 autoconnect no type ethernet ip4 192.168.1.240 gw4 192.168.1.1    
    增加一个使用 DHCP 的新连接

        nmcli connection add type ethernet con-name NEW_DHCP ifname eno16777736
</code></pre></div><p>​<br>​<br>    modify<br>        添加DNS设置到静态连接中<br>            nmcli connection modify “static” ipv4.dns 202.131.124.4<br>             添加更多的DNS<br>                 nmcli connection modify “static” +ipv4.dns 8.8.8.8<br>                     注意：要使用额外的+符号，并且要是+ipv4.dns，而不是ip4.dns。</p>
<div class="hljs code-wrapper"><pre><code>    添加一个额外的ip地址
         nmcli connection modify &quot;static&quot; +ipv4.addresses 192.168.200.1/24

    使用下列命令设置DNS服务器：
        nmcli connection modify NEW ipv4.dns &quot;8.8.8.8 8.8.4.4&quot;

    修改IP地址是静态还是DHCP//  manual为静态none
        nmcli con mod IF-NAME ipv4.method manual | dhcp

del
    删除连接
        nmcli connection del NEW


图形工具
         nm-connection-editor
         nmtui
    改回传统命名方式7
    (1) 编辑/etc/default/grub配置文件
        GRUB_CMDLINE_LINUX=&quot;net.ifnames=0 rhgb quiet&quot;或：&quot;修改/boot/grub2/grub.cfg| biosdevname=0&quot;  
    (2) 为grub2生成其配置文件
        grub2-mkconfig -o /boot/grub2.cfg
    (3) 重启系统            
            Centos6 改网卡名
                /etc/undev/rules.d/70-persistent-net.rulescd
                #cd /etc/undev/rules.d/
                #vim 70-persistent-net.rules  改name 即可
                #reboot

    上面只是对于nmcli命令的简单应用，更多的用法可以参看NetworkManager(8), nmcli(1), nmcli-examples(5), NetworkManager.conf(5) 几个的man手册。


    centos6改主机名
        1.临时修改主机名
            hostname cen7
        2.永久修改主机名
            vi /etc/sysconfig/network
            HOSTNAME=JJ
        3. 
            sysctl kernel.hostname=hadoop
        4\/etc/hosts
            127.0.0.1              localhost.localdomain


                localhost.localdomain 是主机名(hostname)，也就是你待修改的。localhost 是主机名的别名（alias），它会出现在Konsole的提示符下。将第二项修改为你的主机名，第三项可选。
                    #/etc/sysconfig/network网卡/etc/sysconfig/network-scripts/网卡名
                    #/etc/udev/rules.d/70-persistent-net.rules
                    #/etc/resolv.conf


    centos7 主机名
        hostnamectl set-hostname NAME[该主机名
                --static 静态
                --transient 瞬态
                --pretty 灵活
            hostnaemctl --transient set-hostname


iproute2
    # net-tools

    $iproute2

    显示所有已连接的网络接口
        # ip link show 

            $ifconfig -a 

    Assign a IP Address to Specific Interface
        # ip addr add 10.0.0.1 dev eth1
        # ip addr add 192.168.0.100/24 boradcast 192.168.0.12
            +为自动计算
            $ifconfig eth1 10.0.0.1/24 
            $ifconfig eth0:1 192.168.10.10 netmask 255.255.255.0 gw 172.20.0.1 up
                $ip addr list dev eth0 

    Check an IP Address
        # ip addr show
        # ip -6 addr show dev eth1
        # ip addr show dev eth1 

            $ifconfig eth1 


    Remove an IP Address
        #ip addr del 192.168.50.5/24 dev eth1
        #
        ifconfig eth1:1 down #清除别名

            $ifconfig eth1 0 //移除而言，除了给接口分配全0地址外。

    为网络接口分配IPv6地址
        #ip -6 addr add 2002:0db5:0:f102::1/64 dev eth1
            $ifconfig eth1 inet6 add 2002:0db5:0:f102::1/647
    添加别名
        ip addr add 192.168.0.13/24 dev etho label eth0:0

    移除网络设备的IPv6地址
        #ip -6 addr del 2002:0db5:0:f102::1/64 dev eth1

            $ifconfig eth1 inet6 del 2002:0db5:0:f102::1/64

    Enable Network Interface
        # ip link set eth1 up // 开启网络接口
        # ip link set eth1 down
                    $sudo ifconfig eth1 up
                    $sudo ifconfig eth1 down 

    Check Route Table?
        # ip route show

    Add Static Route
        # ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
        # ip route add 192.168.0.100 dev eth0
                        $route add -host 172.18.0.100 dev eth0


    Remove Static Route
        # ip route add 172.16.32.0/24 via 192.168.1.1 dev eth0
        # ip route del 172.16.32.0/24 \

            $route add -net 172.16.32.0/24 gw 192.168.1.1 dev eth0
            $route del -net 172.16.32.0/24 

     Add Persistence Static Routes
         //etc/sysconfig/network-scripts/route-eth0 
             //default route-eth0 file will not be there

         # vi /etc/sysconfig/network-scripts/route-eth0
            10.10.20.0/24 via 192.168.50.100 dev eth0

            For Ubuntu/Debian/Linux Mint
                $ sudo vi /etc/network/interfaces
                        auto eth0
                        iface eth0 inet static
                        address 192.168.50.2
                        netmask 255.255.255.0
                        gateway 192.168.50.100
                        ipadd_start= 
                        ipadd_end=
                        #########{Static Route}###########
            永久添加ip 别名

                如果要永久添加ip别名，则可以在/etc/sysconfig/network-scripts/ 下添加别名配置文件
                配置文件名：ifcfg-eth0:0
                内容：

                    DEVICE=eth0:0
                    IPADDR=192.168.1.111
                    PREFIX=24
                    ONPARENT=yes
             ifup eth0                        
                        up ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0

    Add Default Gateway
        #ip route add default via 192.168.50.100
        #ip route add default via 192.168.1.2 dev eth0
        #ip route replace default via 192.168.1.2 dev eth0 #删除。

            $route add default gw 192.168.1.2 eth0
            $route del default gw 192.168.1.1 eth0 
    ‘
    临时改变接口MAC地址    
        #ip link set dev eth1 address 08:00:27:75:2a:67
            $ifconfig eth1 hw ether 08:00:27:75:2a:66 

    查看ARP表
            # ip neigh 
             $arp -an 

    添加或删除静态ARP项
        #ip neigh add 192.168.1.100 lladdr 00:0c:29:c0:5a:ef dev eth0
        #ip neigh del 192.168.1.100 dev eth0 
            $arp -s 192.168.1.100 00:0c:29:c0:5a:ef
            $arp -d 192.168.1.100 

    添加、删除或查看多播地址
            # ip maddr add 33:44:00:00:00:01 dev eth0
            # ip maddr del 33:44:00:00:00:01 dev eth0 
            # ip maddr list dev eth0 

                $ipmaddr add 33:44:00:00:00:01 dev eth0
                $ipmaddr del 33:44:00:00:00:01 dev eth0
                $ipmaddr show dev eth0
                $netstat -g 

    用包转发：
            # echo &quot;1&quot; &gt; /proc/sys/net/ipv4/ip_forward
</code></pre></div><p>ip link set 命令组 （接口硬件操作相关）<br>ip -s -s link show                                  # 显示所有接口详细信息<br>ip -s -s link show eth1.11                          # 显示单独接口信息<br>ip link set dev eth1 up                             # 启动设备，相当于 ifconfig eth1 up<br>ip link set dev eth1 down                           # 停止设备，相当于 ifconfig eth1 down<br>ip link set dev eth1 txqueuelen 100                 # 改变设备传输队列长度<br>ip link set dev eth1 mtu 1200                       # 改变 MTU 长度<br>ip link set dev eth1 address 00:00:00:AA:BB:CC      # 改变 MAC 地址<br>ip link set dev eth1 name myeth                     # 接口名变更</p>
<p>ip neighbor 命令组 （ARP地址表相关）\\</p>
<p>ip neighbor show                                                # 查看 ARP 表<br>ip neighbor add 10.1.1.1 lladdr 0:0:0:0:0:1 dev eth0 nud permit # 添加一条 ARP 相关表项<br>ip neighbor change 10.1.1.1 dev eth0 nud reachable              # 修改相关表项<br>ip neighbor del 10.1.1.1 dev eth0                               # 删除一条表项<br>ip neighbor flush                                               # 清除整个 ARP 表</p>
<p>ip -6 route add 2000:ff::/80 via 2000:ff04::1 dev eth1.11   # 添加一条路由<br>ip -6 route add default via 2000:ff04::1 dev eth1.11        # 添加默认路由<br>ip -6 route show                                            # 查看完整路由表<br>ip -6 route show dev eth1.11                                # 查看指定接口路由项<br>ip -6 route del 2000:ff04::/64                              # 删除所有相关路由表<br>ip -6 route del 2000:ff04::/64 dev eth1.11                  # 删除相关接口上的路由表<br>ip -6 route change 2000:ff04::/64 dev eth1.12               # 修改路由表项<br>ip route add nat 192.168.10.100 via 202.6.10.1              # 添加 NAT 路由项，将 192 地址转换成 202 地址<br>ip route replace default equalize nexthop via 211.139.218.145 dev eth0 weight 1 nexthop via 211.139.218.145 dev eth1 weight 1   # 添加负载均衡路由</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Network/">Network</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2017/05/04/NginxInstall-and-config/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Nginx 服务器安装及配置文件详解</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2016/12/27/26-Linux-Common-Commands/">
                        <span class="hidden-mobile">26-Linux-Common-Command</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                

              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
